//
//  UserPasswordViewController.m
//  JinMaJiaDemo
//
//  Created by GripMeMory on 16/1/12.
//  Copyright © 2016年 GripMeMory. All rights reserved.
//

#import "UserPasswordViewController.h"
#import "JMJLoginTextField.h"

#define kTextFieldTopMargin 45 / 2
#define kTextFieldLeftMargin 30 / 2
#define kTextFieldSeparateMargin 20 / 2
#define kTextFieldRightMargin 40 / 2
#define kTextFieldBottomMargin 70 / 2
#define kTextFieldWidth 300 / 2
#define kLabelWidth 150 / 2
#define kLabelHeight 55 / 2
#define kButtonWidth 30
#define kButtonRightMargin 10 / 2


@interface UserPasswordViewController ()

@end

@implementation UserPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customNav];
    [self customMainView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.tabBarController.tabBar.hidden = NO;
}

#pragma mark - Custom User Interface

- (void)customNav{
    self.title = @"注册3/3";
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回"] style:UIBarButtonItemStylePlain target:self action:@selector(bbiClick:)];
    self.navigationItem.leftBarButtonItem = bbi;
}

- (void)customMainView{
    UILabel *userLabel = [[UILabel alloc] initWithFrame:CGRectMake(kTextFieldLeftMargin, kNavigationBarHeight + kTextFieldTopMargin + kTextFieldSeparateMargin, kLabelWidth, kLabelHeight)];
    userLabel.text = @"用户名";
    userLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:userLabel];
    
    JMJNormalTextField *userTextField = [[JMJNormalTextField alloc] initWithFrame:CGRectMake(userLabel.right + kTextFieldRightMargin, userLabel.top, UISCREENWIDTH - 2 * kTextFieldLeftMargin - 2 * kButtonRightMargin - kLabelWidth - kButtonWidth - kTextFieldRightMargin, kLabelHeight)];
    userTextField.layer.cornerRadius = 3;
    userTextField.layer.borderWidth = 2;
    userTextField.layer.borderColor = [RGB_COLOR(@"#c9c9c9") CGColor];
    [self.view addSubview:userTextField];
    
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(kTextFieldLeftMargin, userLabel.bottom + kTextFieldSeparateMargin, UISCREENWIDTH - 2 * kTextFieldLeftMargin, 1)];
    view1.backgroundColor = RGB_COLOR(@"#c9c9c9");
    [self.view addSubview:view1];
    
    UILabel *passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(userLabel.left, view1.bottom + kTextFieldSeparateMargin, kLabelWidth, kLabelHeight)];
    passwordLabel.text = @"密码";
    passwordLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:passwordLabel];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(self.view.right - kTextFieldLeftMargin - kButtonWidth - kButtonRightMargin, view1.bottom + kTextFieldSeparateMargin, kButtonWidth, kLabelHeight);
    [button setImage:[UIImage imageNamed:@"密码可视1"] forState:UIControlStateNormal];
    [button setImage:[UIImage imageNamed:@"密码可视"] forState:UIControlStateSelected];
    button.tag = 1;
    button.contentMode = UIViewContentModeCenter;
    [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    JMJNormalTextField *passwordTextField = [[JMJNormalTextField alloc] initWithFrame:CGRectMake(passwordLabel.right + kTextFieldRightMargin, passwordLabel.top, UISCREENWIDTH - 2 * kTextFieldLeftMargin - 2 * kButtonRightMargin - kLabelWidth - kButtonWidth - kTextFieldRightMargin, kLabelHeight)];
    passwordTextField.layer.cornerRadius = 3;
    passwordTextField.layer.borderWidth = 2;
    passwordTextField.layer.borderColor = [RGB_COLOR(@"#c9c9c9") CGColor];
    [self.view addSubview:passwordTextField];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(kTextFieldLeftMargin, passwordLabel.bottom + kTextFieldSeparateMargin, UISCREENWIDTH - 2 * kTextFieldLeftMargin, 1)];
    view2.backgroundColor = RGB_COLOR(@"#c9c9c9");
    [self.view addSubview:view2];
    
    UILabel *passwordLabel2 = [[UILabel alloc] initWithFrame:CGRectMake(userLabel.left, view2.bottom + kTextFieldSeparateMargin, kLabelWidth, kLabelHeight)];
    passwordLabel2.text = @"重复密码";
    passwordLabel2.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:passwordLabel2];
    
    JMJNormalTextField *passwordTextField2 = [[JMJNormalTextField alloc] initWithFrame:CGRectMake(passwordLabel2.right + kTextFieldRightMargin, passwordLabel2.top, UISCREENWIDTH - 2 * kTextFieldLeftMargin - 2 * kButtonRightMargin - kLabelWidth - kButtonWidth - kTextFieldRightMargin, kLabelHeight)];
    passwordTextField2.layer.cornerRadius = 3;
    passwordTextField2.layer.borderWidth = 2;
    passwordTextField2.layer.borderColor = [RGB_COLOR(@"#c9c9c9") CGColor];
    [self.view addSubview:passwordTextField2];
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(self.view.right - kTextFieldLeftMargin - kButtonWidth - kButtonRightMargin, view2.bottom + kTextFieldSeparateMargin, kButtonWidth, kLabelHeight);
    [button2 setImage:[UIImage imageNamed:@"密码可视1"] forState:UIControlStateNormal];
    [button2 setImage:[UIImage imageNamed:@"密码可视"] forState:UIControlStateSelected];
    button2.tag = 2;
    button2.contentMode = UIViewContentModeCenter;
    [button2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];
    
    UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    commitBtn.frame = CGRectMake(kTextFieldLeftMargin, passwordLabel2.bottom + kTextFieldBottomMargin, UISCREENWIDTH - 2 * kTextFieldLeftMargin, kLabelHeight + 2 * kTextFieldSeparateMargin);
    [commitBtn setBackgroundColor:RGB_COLOR(@"#d91f00")];
    [commitBtn setTitle:@"注册完成" forState:UIControlStateNormal];
    [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    commitBtn.layer.cornerRadius = 5;
    [commitBtn addTarget:self action:@selector(registerButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:commitBtn];
}

#pragma mark - Actions

- (void)bbiClick:(UIBarButtonItem *)bbi{
    [self.navigationController popViewControllerAnimated:NO];
}

- (void)btnClick:(UIButton *)btn{
    btn.selected = !btn.selected;
}

- (void)registerButtonClick{
    
}

@end
